package com.ktg.mes.qc.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.qc.mapper.QcItemTestingResultSortMapper;
import com.ktg.mes.qc.domain.QcItemTestingResultSort;
import com.ktg.mes.qc.service.IQcItemTestingResultSortService;



/**
 * 产品检测记录排序Service业务层处理
 *
 * @author byteco
 * @date 2023-01-31
 */
@Service
public class QcItemTestingResultSortServiceImpl extends ServiceImpl<QcItemTestingResultSortMapper, QcItemTestingResultSort> implements IQcItemTestingResultSortService
{




    /**
     * 查询产品检测记录排序
     *
     * @param entity 产品检测记录排序
     * @param page 分页对象
     * @return 产品检测记录排序
     */
    @Override
    public IPage<QcItemTestingResultSort> queryPageList(QcItemTestingResultSort entity, Page<QcItemTestingResultSort> page) {
        QueryWrapper<QcItemTestingResultSort> lqw = new QueryWrapper<QcItemTestingResultSort>(entity);
        lqw.orderByAsc("sort_index");
        IPage<QcItemTestingResultSort> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询产品检测记录排序
     *
     * @param entity 产品检测记录排序
     * @return 产品检测记录排序
     */
    @Override
    public List<QcItemTestingResultSort> queryList(QcItemTestingResultSort entity) {
        QueryWrapper<QcItemTestingResultSort> lqw = new QueryWrapper<QcItemTestingResultSort>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public QcItemTestingResultSort getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增产品检测记录排序
     *
     * @param entity 产品检测记录排序
     * @return 结果
     */
    @Override
    public void insert(QcItemTestingResultSort entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改产品检测记录排序
     *
     * @param entity 产品检测记录排序
     * @return 结果
     */
    @Override
    public boolean update(QcItemTestingResultSort entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除产品检测记录排序
     *
     * @param recordIds 需要删除的产品检测记录排序主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] recordIds)
    {
        return this.removeByIds(Arrays.asList(recordIds));
    }

    /**
     * 删除产品检测记录排序信息
     *
     * @param recordId 产品检测记录排序主键
     * @return 结果
     */
    @Override
    public boolean delete(Long recordId)
    {
        return this.removeById(recordId);
    }

    private LambdaQueryWrapper<QcItemTestingResultSort> buildQueryWrapper(QcItemTestingResultSort entity) {
        LambdaQueryWrapper<QcItemTestingResultSort> lqw = Wrappers.lambdaQuery();
                    lqw.eq(StringUtils.isNotBlank(entity.getCode()), QcItemTestingResultSort::getCode, entity.getCode());
                    lqw.like(StringUtils.isNotBlank(entity.getSortName()), QcItemTestingResultSort::getSortName, entity.getSortName());
        return lqw;
    }
}
